//
//  TaskDiaoDuOrderVC.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2021/4/2.
//  Copyright © 2021 吕晶. All rights reserved.
//

#import "TaskDiaoDuOrderVC.h"
#import "TaskDiaoDuOrderModel.h"
#import "TaskDiaoDuOrderCell.h"
#import "TaskDiaoDuOrderGoodVC.h"

@interface TaskDiaoDuOrderVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation TaskDiaoDuOrderVC

//-(NSMutableArray<TaskDiaoDuOrderModel *> *)dataArray {
//    if (!_dataArray) {
//        _dataArray = [NSMutableArray array];
//    }
//    return _dataArray;
//}

-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, ScreenH - NaviHeight - BottomHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = Color_backgroundColor;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"任务详情";
    [self.view addSubview:self.tableView];
    [self.tableView reloadData];
    UIButton *editBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 88, 30)];
    [editBtn setTitle:@"确认" forState:0];
    [editBtn setTitleColor:HexColor(0xffffff) forState:0];
    editBtn.titleLabel.font = BoldFontOfSize(14);
    editBtn.backgroundColor = Color_ThemeColor;
    editBtn.layer.masksToBounds = YES;
    editBtn.layer.cornerRadius = 15;
    [editBtn addTarget:self action:@selector(sureClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:editBtn];
}

- (void)sureClick {
    if (self.finishBlock) {
        self.finishBlock();
    }
    [self.rt_navigationController popViewControllerAnimated:YES];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TaskDiaoDuOrderCell *cell = [TaskDiaoDuOrderCell TaskDiaoDuOrderCellWithTableView:tableView];
    TaskDiaoDuOrderModel *model = self.dataArray[indexPath.section];
    cell.model = model;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    TaskDiaoDuOrderCell *cell = [TaskDiaoDuOrderCell TaskDiaoDuOrderCellWithTableView:tableView];
    TaskDiaoDuOrderModel *model = self.dataArray[indexPath.section];
    cell.model = model;
    return cell.height;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    TaskDiaoDuOrderGoodVC *vc = [TaskDiaoDuOrderGoodVC new];
    vc.goods_list = self.dataArray[indexPath.section].goods_list;
    __weak_self;
    vc.finishBlock = ^(NSMutableArray<TaskDiaoDuOrderGoodModel *> * _Nonnull goods_list) {
        weakself.dataArray[indexPath.section].goods_list = goods_list;
        [tableView reloadData];
    };
    [self.rt_navigationController pushViewController:vc animated:YES];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 10)];
//    view.backgroundColor = Color_backgroundColor;
//    return view;
    return [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 10)];
    view.backgroundColor = Color_backgroundColor;
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

@end
